/**
* @Title: auditFeedback_ctrl.js
* @Description: TODO
* Copyright: Copyright (c) 2014 
 * Company:中国平安
*
* @Project HIMS-FWA
* @author EX-XIEQI001
* @date 2014年11月19日 上午15:06:02
* @version V1.0
*/
;
(function(){
	'use strict';
	
	var app = angular.module('fwa.mainApp');
	app.controller('AuditFeedbackCtrl', ['$scope', '$rootScope','FwaTabsetService','CommunityService','AuditFeedbackService','Modal','AuditDictServices',
	                                       function($scope, $rootScope,FwaTabsetService,CommunityService,AuditFeedbackService,Modal,AuditDictServices){
			
		
		$scope.auditDictServices = AuditDictServices;
		AuditDictServices.initCodeListDatas();
		
		$scope.form = {};
		//分页配置
		$scope.current = {
							totalCount: 0,
							currentPage:0,
							limit:20
						 };
		var cellTemplate = '<a ng-show="data.caseStatus != 4" ng-click="detail(data);">查看</a><a ng-show="data.caseStatus == 4" ng-click="confirm(data);">确认</a>';
		var cellTemplate2 = '<span ng-show="data.caseStatus != 4" >已确认</span><span ng-show="data.caseStatus == 4" >待确认</span>';
		$scope.columns = [
		                  {label:"案件编号",map:"caseCode",width:"14%"},
		                  {label:"案件要点",map:"keyPoint",width:"14%"},
		                  {label:"稽核时段",map:"periodBeginDate",width:"18%",cellTemplate:'<span ng-bind="data.periodBeginDate"></span>-<span ng-bind="data.periodEndDate"></span>'},
		                  {label:"确认截止时间",map:"affirmDeadline",width:"16%"},
		                  {label:"案发时间",map:"auditDate",width:"14%"},
		                  {label:"状态",map:"statusName",width:"14%",cellTemplate:cellTemplate2},
		                  {label:"操作",map:"1",width:"10%",cellTemplate:cellTemplate}
		                  ];
		
		//确定
		$scope.confirm = function(data) {
			FwaTabsetService.selectTab("thisLetter.confirm",{
				caseCode:data.caseCode
			});
		}
		
		//查看
		$scope.detail = function(data) {
			FwaTabsetService.selectTab("thisLetter.detail",{
				caseCode:data.caseCode
			});
		}
		//查询
		$scope.onSubmit = function() {
			$scope.current.currentPage = 1;
			query();
		}
		
		function query() {
			var startDate = '', endDate = '';
			
			if ($scope.form.date && $scope.form.date.start) {
				startDate = $scope.form.date.start;
			}
			
			if ($scope.form.date && $scope.form.date.end) {
				endDate = $scope.form.date.end;
			}
			var params = {
						page : $scope.current.currentPage,
						limit : $scope.current.limit,
						caseCode : $scope.form.caseCode,
						keyPoint : $scope.form.keyPoint,
						startDate : startDate,
						endDate : endDate
					};
			if($scope.form.caseStatus && $scope.form.caseStatus != ""){
				if($scope.form.caseStatus == 5){
					params.caseStatus= null;
				}else{
					params.caseStatus = $scope.form.caseStatus;
				}
			}else{
				params.caseStatus= null;
				params.queryAll= "\'4\',\'5\',\'6\',\'7\'";
			}
			AuditFeedbackService.query(params).success(function(res){
				$scope.tableData = res.result;
				$scope.current.totalCount = res.totals.total;
			}).error(function(e){
				Modal.alert(e.msg);
			});
		}
       $rootScope.$on('$stateChangeSuccess', function(event, toState, toParam, from, fromParam ) {
           if(toState.name && toState.name.indexOf('auditFeedback') != -1) {
               $scope.onSubmit();
           }
       });
		$scope.onSubmit();
		
		//重置
		$scope.onReset = function() {
			$scope.form.date ={start:null,end:null};
			$scope.form.caseStatus = null;
			$scope.form.caseCode = null;
			$scope.form.keyPoint = null;
		}
		
		//分页监听
		$scope.$on('pageTool.skipPage',function(e,v){
			$scope.current.currentPage = v;
			query();
		});
		
	}]);
})();
